# 冒泡排序算法: 借用两层循环，while层计算比较次数，
def sortFunc(numArray):
  loopTimes = 0; # 记录循环冒泡比较次数
  while loopTimes < len(numArray) - 1:
    # 索引比较
    for index in range(len(numArray) - loopTimes - 1):
      if numArray[index] > numArray[index + 1]:
        tmp = numArray[index]
        numArray[index] = numArray[index+1]
        numArray[index+1] = tmp
    loopTimes=loopTimes+1
  print('COMPARE TIMES', loopTimes)
  return numArray

unSortedArray = [1,3,4,2,3,5,7,8,9]
print(unSortedArray, len(unSortedArray))
print(sortFunc(unSortedArray))